package com.lu.controller;

import com.lu.mapper.UserMapper;
import com.lu.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin
@Api(tags = "User")
@RestController
public class UserController {
//        http://localhost:8080/doc.html请求地址
    @Resource
    private UserMapper userMapper;

    @ApiOperation("获取全部用户")
    @GetMapping("/getUsers")
    public List<User> getUsers() {
        return userMapper.selectList(null);
    }
    @ApiOperation("获取用户")
    @GetMapping("/getUser/{name}/{pwd}")
    public List<User> getUser(@PathVariable("name")String name,@PathVariable("pwd")String pwd) {
        System.out.println(name+pwd);
        Map<String, Object> map = new HashMap<>();
        map.put("user_name",name);
        map.put("password",pwd);
        return userMapper.selectByMap(map);
    }
    @ApiOperation("添加用户")
    @PostMapping("/InsertUser/{name}/{FullName}/{pwd}")
    public int InsertUser(@PathVariable("name")String name,@PathVariable("FullName")String FullName,@PathVariable("pwd")String pwd) {
        User user = new User();
        user.setUserName(name);
        user.setFullName(FullName);
        user.setPassword(pwd);
        user.setRole(0);
        return userMapper.insert(user);
    }

    @ApiOperation("删除用户")
    @PostMapping("/DeleteUser/{id}")
    public int DeleteUser(@PathVariable("id")int id) {
        return userMapper.deleteById(id);
    }


}
